// 面试 stl promise,future
#include <chrono>
#include <future>
#include <iostream>
using namespace std;

void Thread_Fun1(std::promise<int> &p) {
  std::this_thread::sleep_for(std::chrono::seconds(2));
  int iVal = 233;
  std::cout << "send(int)=" << iVal << std::endl;
  p.set_value(iVal);
}

void Thread_Fun2(std::future<int> &f) {
  auto iVal = f.get();  // block until get iVal = 233
  std::cout << "recv(int)=" << iVal << std::endl;
}

void testPromise() {
  std::promise<int> pr1;
  std::future<int> fu1 = pr1.get_future();
  std::thread t1(Thread_Fun1, std::ref(pr1));
  std::thread t2(Thread_Fun2, std::ref(fu1));
  t1.join();
  t2.join();
}
